﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using JEng_Mark_1.SceneObject.SceneGraph;
using JEng_Mark_1.SceneObject;
using JEng_Mark_1.GameComponents;

namespace JEng_Mark_1.Managers
{
    public class JSceneGraphManager : GameComponent
    {
        private static JNode _root;

        /// <summary>
        /// The root of the scene graph
        /// </summary>
        public static JNode Root
        {
            get { return _root; }
        }

        /// <summary>
        /// Create the SceneGraph manager
        /// </summary>
        /// <param name="game">The XNA game object</param>
        public JSceneGraphManager(Game game)
            : base(game)
        {
            _root = new JNode();
        }

        /// <summary>
        /// Draw all objects in the scene graph
        /// </summary>
        /// <param name="gameTime"></param>
        public static void Draw(GameTime gameTime)
        {
            _root.Draw(gameTime);
        }

        /// <summary>
        /// Load the content of all objects in the scene graph
        /// </summary>
        public static void LoadContent()
        {
            _root.LoadContent();
        }

        /// <summary>
        /// Unload the content of all object in the scene graph
        /// </summary>
        public static void UnloadContent()
        {
            _root.UnloadContent();
        }

        /// <summary>
        /// Add an object to the scene graph
        /// </summary>
        /// <param name="newObject"></param>
        public static void AddObject(JSceneObject newObject)
        {
            JSceneObjectNode node = new JSceneObjectNode(newObject);
            _root.AddNode(node);
            JLog.addMessage("Added object to scene graph " + newObject.ModelName);
        }
    }
}
